package com.zcc.springbootneo4j.dao;

import com.zcc.springbootneo4j.entity.Drugs;
import org.springframework.data.neo4j.annotation.Query;
import org.springframework.data.neo4j.repository.Neo4jRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Component;

import java.util.List;

/**
*@author 范晓炜
*@date 2022/10/14
*/

/**
 * 节点间的关系
 */
@Component
public interface Relationship extends Neo4jRepository<Relationship,Long> {
    /**
     * 查询药物是否可治疗疾病
     * @param ywmc
     * @param name
     * @return
     */
    @Query("MATCH (a:药物),(b:疾病) WHERE a.ywmc =$ywmc AND b.name =$name return a,b")
    List<Relationship> findDrugTherapy(@Param("ywmc") String ywmc, @Param("name") String name);

    /**
     * 增加药物所治疗可治疗的病症
     * @param ywmc
     * @param name
     * @return
     */
    @Query("MATCH (a:药物),(b:疾病)\n" +
            "WHERE a.name = $ywmc AND b.name = $name" +
            "CREATE (a)-[r:治疗] -> (b)\n" +
            "RETURN r")
    List<Relationship> addDrugTherapy(@Param("ywmc") String ywmc, @Param("name") String name);
    /**
     * 增加身体不舒服产生的症状
     * @param name
     * @return
     */
    @Query( "MATCH (a:身体不舒服),(b:疾病)\n" +
            "WHERE a.name = '身体不舒服' AND b.name = $name " +
            "CREATE (a)-[r:生病] -> (b)\n" +
            "RETURN r" )
    List<Relationship> addDisease(@Param("name") String name);


    /**
     * 删除(身体不舒服会产生症状)关系
     */
    @Query("MATCH (n:身体不舒服)-[r]->(m:疾病{name:$name}) delete r")
    List<Relationship> deleteDiseaseRS(@Param("name")String name);

    /**
     * 删除关系
     */
    @Query("MATCH (n:药物{ywmc:$nameO})-[r]->(m:疾病{name:$nameT}) delete r")
    List<Relationship> deleteRelationship(@Param("nameO")String nameO,@Param("nameT") String nameT);
}
